Dart BigInt operator ==
Syntax & Examples
BigInt.operator == operator
The `operator ==` in Dart checks for equality between two objects.
Syntax of BigInt.operator ==
The syntax of BigInt.operator == operator is:
operator ==(dynamic other) → boolThis operator == operator of BigInt the equality operator.
Parameters
| Parameter | Optional/Required | Description |
|---|---|---|
other | required | the object to compare for equality |
✐ Examples
1 Check equality of strings
In this example,
- We create two string variables,
str1andstr2, with the same value 'Hello'. - We use the
==operator to check ifstr1is equal tostr2. - We print the result of the comparison to standard output.
Dart Program
void main() {
String str1 = 'Hello';
String str2 = 'Hello';
bool isEqual = str1 == str2;
print('Are str1 and str2 equal? $isEqual');
}Output
Are str1 and str2 equal? true
2 Check equality of integers
In this example,
- We create two integer variables,
num1andnum2, with different values. - We use the
==operator to check ifnum1is equal tonum2. - We print the result of the comparison to standard output.
Dart Program
void main() {
int num1 = 5;
int num2 = 10;
bool isEqual = num1 == num2;
print('Are num1 and num2 equal? $isEqual');
}Output
Are num1 and num2 equal? false
3 Check equality of lists
In this example,
- We create two list variables,
list1andlist2, with the same contents. - We use the
==operator to check iflist1is equal tolist2. - We print the result of the comparison to standard output.
Dart Program
void main() {
List<int> list1 = [1, 2, 3];
List<int> list2 = [1, 2, 3];
bool isEqual = list1 == list2;
print('Are list1 and list2 equal? $isEqual');
}Output
Are list1 and list2 equal? true
Summary
In this Dart tutorial, we learned about operator == operator of BigInt: the syntax and few working examples with output and detailed explanation for each example.